package com.hb.config;

import com.hb.aspect.TrackCounter;
import com.hb.impl.BlankDisc;
import com.hb.interfaces.CompactDisc;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

import java.util.ArrayList;
import java.util.List;

@Configuration
@EnableAspectJAutoProxy
@ComponentScan(basePackageClasses = TrackCounter.class)
public class TrackCounterConfig {
    @Bean
    public CompactDisc blankDisc() {
        BlankDisc bd = new BlankDisc();
        bd.setTitle("Sgt. Pepper's Lonely Hearts Club Band");
        bd.setArtist("The Beatles");
        List<String> tracks = new ArrayList<String>();
        tracks.add("Sgt. Pepper's Lonely Hearts Club Band");
        tracks.add("With a Little Help from My Friends");
        tracks.add("Lucy in the Sky with Diamonds");
        tracks.add("Getting Better");
        tracks.add("Fixing a Hole");
        tracks.add("Hai Kuo Tian Kong");
        tracks.add("Na Xie Hua Er");
        bd.setTracks(tracks);

        return bd;
    }

    /**
     * 经过测试发现使用了 @Aspect 注解的类也还是要进行 Bean 配置，开始的猜想认为自动配置加上 @EnableAspectJAutoProxy 扫描到 @Aspect 时就会把 @Aspect 标注的类
     * 配置为 Bean，不需要我们再去进行 Bean 配置，结果 @Aspect 标注的切面类里面的功能不起效，只有进行了 Bean 配置才会起效。
     * @return
     */
    @Bean
    public TrackCounter trackCounter() {
        return new TrackCounter();
    }
}
